package org.hyl.javabase.model;

public class bridgeDemo {
	public static void main(String[] args) {

		Bridge bridge = new MyBridge();

		Sourceable source1 = new SourceSub1();
		Sourceable source2 = new SourceSub2();
		
		
		Sourceable so=null;
		so=source1;
		so.method();
		so=source2;
		so.method();
		/* ���õ�һ������ */
		
		bridge.setSource(source1);
		bridge.method();

		/* ���õڶ������� */
	
		bridge.setSource(source2);
		bridge.method();
	}
}

class SourceSub1 implements Sourceable {

	public void method() {
		System.out.println("this is the first sub!");
	}
}

class SourceSub2 implements Sourceable {

	public void method() {
		System.out.println("this is the second sub!");
	}
}

abstract class Bridge {
	private Sourceable source=null;

	public void method() {
		source.method();
	}

	public Sourceable getSource() {
		return source;
	}

	public void setSource(Sourceable source) {
		this.source = source;
	}
}

class MyBridge extends Bridge {
	public void method() {
		getSource().method();
	}
}